<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="white" />
		<meta name="format-detection" content="telephone=no" />
		<!--Iphpone电话号码串识别 -->
		<meta http-equiv="x-rim-auto-match" content="none" />
		<!--电话号码串识别 -->
		<title>拨云见日科技</title>
		<link rel="SHORTCUT ICON" href="/static/favicon.ico" type="image/x-icon"/>
		<script src='/static/js/jquery.js' type='text/javascript'></script>
		<script src='/static/js/qrcode.js' type='text/javascript'></script>
		<script src='/static/js/layui.js' type='text/javascript'></script>
		<link href="/static/css/index.css" rel="stylesheet" type="text/css" />
		<link href="/static/css/layui.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		{% include "base.html" %}
		<div class="wrapper">
			<!--功能二维码-->
			<div class="wrapper_cont">
				<div class="duty">选择采购单</div>
			</div>
			{% include "right.html" %}
			<div>
				<table class="layui-table" style="width:90%">
					<tbody id="mylist">
				  </tbody>
				</table>
			</div>
		</div>
	</body>
	<script type='text/javascript'>
		$(function(){
			document.getElementById("v").value="";
			loadData();
			getValue();
		})
		function loadData(){
			var supplier_id = '{{data}}';
			var action = $("#mm").attr("action")
			var sql = "select po.id,po.name,po.date_approve,po.state,po.amount_total "+
					",(select string_agg(name||'，数量：'||product_qty||'，已收：'||qty_received,'<br/>') from purchase_order_line where order_id = po.id) "+
					" from purchase_order po  "+
				 	" LEFT JOIN res_partner rp on po.partner_id = rp.id LEFT JOIN res_users ru on ru.id = po.user_id "+
				 	" where  rp.id = "+supplier_id +" and po.state='purchase' and po.state != 'done' order by po.date_approve desc"
			$.post(action,{sql:sql},function(result){
				result = JSON.parse(result);
				for(v in result){
					var id = "li_"+result[v][0]
					var html = "<tr>" +
							"<td>"+result[v][1]+"</td>" +
							"<td>"+result[v][2]+"</td>" +
							"<td>¥"+result[v][4]+"</td>" +
							"<td style='width:400px'>"+result[v][5]+"</td>" +
							"<td colspan='4' style='width: 100px;text-align: center'><ul id='"+id+"'></ul></td>" +
							"</tr>"
					$("#mylist").append(html)
				}

				for(v in result){
					var id = "li_"+result[v][0]
					new QRCode(document.getElementById(id), {
						text: "0"+result[v][0],
						colorDark: '#000000',
						colorLight: '#ffffff',
						width:100,
						height:100,
						correctLevel: QRCode.CorrectLevel.H
					});
				}
			});
		}

		function getValue(){
                v = document.getElementById('v').value;
                if(!v) {
					$("#v").focus();
					setTimeout(getValue, 1000);
					return;
				}
               	var robot_id = "{{getSession('robot_id')}}"
				if(commFun(v,robot_id)){
					return;
				}
                if(v){
                	var id = "li_"+v
					if($("#"+id).length==0){
						document.getElementById('v').value = "";
						layer.msg("无效订单")
						setTimeout(getValue, 1000);
						return;
					}
                	document.getElementById('v').value = "";
					setSession("orderid",v);
					setTimeout(function(){
						 location.href = "index.html?data="+robot_id
					},2000)
                }
            }
	</script>

	{% include "footer.html" %}
</html>
